﻿using System;
using System.Collections.Generic;
using System.Web;
using InfoSite.Data;

namespace InfoSite.Tools.Storage
{
	public class SessionHelper
	{
		private enum Keys
		{
			ActiveUser,
			LastException,
			RemindedUser,
			ResetPasswordStatus,
			UserList,
            Url
		}

		public static Exception LastException
		{
			get
			{
				object oLastException = Get(Keys.LastException);
				return (oLastException != null) ? (Exception)oLastException : null;
			}
			set
			{
				Set(Keys.LastException, value);
			}
		}

		public static SiteUserExtended ActiveUser
		{
			get
			{
				object oActiveUser = Get(Keys.ActiveUser);
				return oActiveUser != null ? (SiteUserExtended)oActiveUser : null;
			}
			set
			{
				Set(Keys.ActiveUser, value);
			}
		}

		public static List<SiteUserExtended> UserList
		{
			get
			{
				object oUserList = Get(Keys.UserList);
				return oUserList != null ? (List<SiteUserExtended>)oUserList : null;
			}
			set
			{
				Set(Keys.UserList, value);
			}
		}

		public static SiteUserExtended RemindedUser
		{
			get
			{
				object oRemindedUser = Get(Keys.RemindedUser);
				return oRemindedUser != null ? (SiteUserExtended)oRemindedUser : null;
			}
			set
			{
				Set(Keys.RemindedUser, value);
			}
		}

		public static bool? ResetPasswordStatus
		{
			get
			{
				object oResetPasswordStatus = Get(Keys.ResetPasswordStatus);
				return oResetPasswordStatus != null ? Convert.ToBoolean(oResetPasswordStatus) : (bool?) null;
			}
			set
			{
				Set(Keys.ResetPasswordStatus, value);
			}
		}

        public static string Url
        {
            get
            {
                object oUrl = Get(Keys.Url);
                return oUrl.ToString();
            }
            set
            {
                Set(Keys.Url, value);
            }
        }

		#region Private methods

		private static object Get(Keys sessionKey)
		{
			return HttpContext.Current.Session[sessionKey.ToString()];
		}

		private static void Set(Keys sessionKey, object sessionValue)
		{
			HttpContext.Current.Session[sessionKey.ToString()] = sessionValue;
		}

		#endregion

		#region Public methods

		#endregion
	}
}
